home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcplusx.zip / TESTEVT.CPP < prev    next >
C/C++ Source or Header  |  1991-02-27  |  4KB  |  156 lines

  1. //
  2. // testevt.cpp        - test module for class Event and EventManager
  3. // Author            - Robin W. McKean
  4. // Last Update        - February 23,1991
  5. // Copyright (C) 1991 All rights reserved
  6. //
  7. //
  8.  
  9. // Interface dependencies ---------------------------------------------------
  10. // None
  11. // End interface dependencies -----------------------------------------------
  12.  
  13. // Implementation dependencies ----------------------------------------------
  14.  
  15. #ifndef _EVENTMGR_H
  16. #include <eventmgr.h>
  17. #endif
  18.  
  19. #ifndef _CURSOR_H
  20. #include <cursor.h>
  21. #endif
  22.  
  23. #ifndef _KEYBOARD_H
  24. #include <keyboard.h>
  25. #endif
  26.  
  27. #ifndef _MOUSE_H
  28. #include <mouse.h>
  29. #endif
  30.  
  31. #ifndef _IOSTREAM_H
  32. #include <iostream.h>
  33. #endif
  34.  
  35. #ifndef _DOS_H
  36. #include <dos.h>
  37. #define _DOS_H
  38. #endif
  39.  
  40. // End implementation dependencies ------------------------------------------
  41.  
  42. EventManager     *theEventManager;
  43. Mouse           *theMouse;
  44. Keyboard        *theKeyboard;
  45. Cursor            *theCursor;
  46.  
  47. void errorExit( char *string );
  48. void processEvent( const Event& theEvent );
  49.  
  50. // Main Module //
  51.  
  52. #pragma argsused
  53. int main( int argc, char **argv )
  54. {
  55.     // Create our event manager from the heap
  56.     theEventManager = new EventManager( 50 );
  57.  
  58.     // Create our devices for input from the heap
  59.     theMouse = new Mouse;
  60.     theKeyboard = new Keyboard;
  61.     theCursor = new Cursor;
  62.  
  63. // Body Comment -------------------------------------------------------------
  64. //
  65. //        We add the devices to the event manager.  We add the pointers, becuase
  66. //        the overloaded operator += takes a Object&.
  67. //
  68. // End ----------------------------------------------------------------------
  69.  
  70.     *theEventManager += *theMouse;
  71.     *theEventManager += *theKeyboard;
  72.     *theEventManager += *theCursor;
  73.  
  74.     // Turn off the cursor because its in the way
  75.     theEventManager->hideDevice( cursorClass );
  76.  
  77.     Event theEvent;
  78.  
  79.     do {
  80.  
  81.         theEventManager->getEvent( theEvent );
  82.         if( theEvent.typeCode != 27 ) 
  83.         {
  84.             theEventManager->hideDevice( mouseClass );
  85.             processEvent( theEvent );
  86.             theEventManager->showDevice( mouseClass );
  87.         }
  88.  
  89.     } while( theEvent.typeCode != 27 );
  90.  
  91.     // Turn the cursor back on
  92.     theEventManager->showDevice( cursorClass );
  93.  
  94. // Body Comment -------------------------------------------------------------
  95. //
  96. //        We do not have to destroy our devices, because, when the event manager
  97. //        is destroyed, the devices added to him will automatically be done so.
  98. //
  99. // End ----------------------------------------------------------------------
  100.                           
  101.     delete theEventManager;
  102.  
  103.     return( 0 );
  104. }
  105.  
  106. void errorExit( char *string )
  107. {
  108.     if( string ) cout << "\ntestevt: " << string << "\n\n";
  109. }
  110.                                
  111. void processEvent( const Event& theEvent )
  112. {
  113.     cout << "\nEvent Type: ";
  114.                                 
  115.     switch( theEvent.type )
  116.     {
  117.         case E_KEY:
  118.             cout << "Keyboard ==> " << hex;
  119.             cout << "Shift State: " << "0x" << theEvent.shiftState << "\t";
  120.             cout << "Key Code: 0x" << theEvent.typeCode << "\n\n" << dec;
  121.             break;
  122.         case E_MOUSE:
  123.             cout << "Mouse ==> ";
  124.             switch( theEvent.typeCode )
  125.             {
  126.                 case M_LEFT_SELECT:
  127.                     cout << "Left button is pressed!" << "\n\n";
  128.                     break;
  129.                 case M_MIDDLE_SELECT:
  130.                     cout << "Middle button is pressed!" << "\n\n";
  131.                     break;
  132.                 case M_RIGHT_SELECT:
  133.                     cout << "Right button is pressed!" << "\n\n";
  134.                     break;
  135.                 case M_MIDDLE_RELEASE:
  136.                     cout << "Middle button is released!" << "\n\n";
  137.                     break;
  138.                 case M_LEFT_RELEASE:
  139.                     cout << "Left button is released!" << "\n\n";
  140.                     break;
  141.                 case M_RIGHT_RELEASE:
  142.                     cout << "Right button is released!" << "\n\n";
  143.                     break;
  144.                 case M_RCONTINUE_SELECT:
  145.                     cout << "Right button is still pressed!\n\n";
  146.                     break;
  147.                 case M_LCONTINUE_SELECT:
  148.                     cout << "Left button is still pressed!\n\n";
  149.                     break;
  150.                 case M_MCONTINUE_SELECT:
  151.                     cout << "Middle button is still pressed!\n\n";
  152.                     break;
  153.             }
  154.     }
  155. }
  156.